<template>
  <div class="banner-container">
    <el-table v-loading="listLoading" :data="list">
      <el-table-column
        align="center"
        label="ID"
        prop="id"
        show-overflow-tooltip
        width="55"
      />
      <el-table-column
        align="center"
        label="用户"
        prop="nickname"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="电话"
        prop="mobile"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="反馈内容"
        prop="content"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="图片">
        <template #default="{ row }">
          <el-image :preview-src-list="srcList" :src="row.img" />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="反馈时间"
        prop="created_at"
        show-overflow-tooltip
      />
      <!-- <el-table-column align="center" label="操作" width="85">
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">编辑</el-button>
          <el-button type="text" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </div>
</template>

<script>
  import { getSuggestionsList as getList } from '@/api/userMessage'

  export default {
    name: 'Suggestions',
    data() {
      return {
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNo: 1,
          pageSize: 10,
        },
        srcList: [],
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      handleEdit(row) {
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        const { list, total } = data
        let srcList = list.map((item) => {
          return item.img
        })
        this.srcList = srcList
        this.list = list
        this.total = total
        this.listLoading = false
      },
    },
  }
</script>
